package org.programmers.anonymous.fightrobots.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.programmers.anonymous.fightrobots.controller.WeaponController;
import org.programmers.anonymous.fightrobots.model.IWeapon;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value="/weapon")
public class WeaponWebController implements BeanFactoryAware
{
	protected WeaponController weaponController = null;
	

	@RequestMapping(value="/list" ,method = RequestMethod.GET)
	public String getListWeapon(ModelMap model){
			
			model.addAttribute("weaponlist", weaponController.getAllWeapons());
			
			return "listWeapon";
	}

	@RequestMapping(value="/" ,method = RequestMethod.GET)
	public String getWeapons(ModelMap model){
			
	     	Map<Integer,String> weaponMap=new HashMap<Integer,String>();
	     	 
	     	for (IWeapon iWeapon: weaponController.getAllWeapons()){
	     		weaponMap.put(iWeapon.getIdWeapon(),iWeapon.getName());	     		
	     	}
			model.addAttribute("weaponmap", weaponMap);
			
			return "listWeapon";
	}

//	@RequestMapping(value="/getWeapon", method = RequestMethod.GET)
//	public @ResponseBody IWeapon receiveMessage(@RequestParam(value="weaponId", required=true) String weaponId, ModelMap model)

	
	

	@Override
	public void setBeanFactory(BeanFactory context) throws BeansException {
		weaponController = (WeaponController)context.getBean("weaponController");
	}
}